﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuadraticEquationPresenter;
using Infrastructure;

namespace WPFView
{
    /// <summary>
    /// Логика взаимодействия для MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, IQuadraticEquationView
    {
        private FactoryLogger factoryLogger;
        public MainWindow()
        {
            factoryLogger = new FactoryLogger();
            InitializeComponent();
            Presenter presenter = new Presenter(this, factoryLogger);
        }

        public event Action solveButtonPressed;
        public event Action showLogButtonPressed;
        public event Action<bool> loggerStateChangedToFileLogger;


        private void SolveButton_Click(object sender, RoutedEventArgs e)
        {
            solveButtonPressed();
        }

        public string aField
        {
            get
            {
                return textBoxA.Text;
            }
        }

        public string bField
        {
            get
            {
                return textBoxB.Text;
            }
        }
        public string cField
        {
            get
            {
                return textBoxC.Text;
            }
        }
        public string x1Field
        {
            set
            {
                textBoxX1.Text = value;
            }
        }
        public string x2Field
        {
            set
            {
                textBoxX2.Text = value;
            }
        }
        public string messageAboutRootsField
        {
            set
            {
                messageAboutRoots.Content = value;
            }
        }
        public string errorMessageField
        {
            set
            {
                errorMessage.Content = value;
            }
        }
        public string logText
        {
            get
            {
                return LogTextBlock.Text;
            }
            set
            {
                LogTextBlock.Text = value;
            }
        }

        private void showLogButton_Click(object sender, RoutedEventArgs e)
        {
            showLogButtonPressed();
        }

        private void fileLoggerRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (sender is RadioButton)
            {
                RadioButton loggerButton = (RadioButton)sender;
                if (loggerStateChangedToFileLogger != null)
                {
                    loggerStateChangedToFileLogger(true);
                }
            }
        }

        private void HTMLLoggerRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (sender is RadioButton)
            {
                RadioButton loggerButton = (RadioButton)sender;
                if (loggerStateChangedToFileLogger != null)
                {
                    loggerStateChangedToFileLogger(false);
                }
            }
        }
    }
}
